<template>
  <el-card class="box-card">
    <!-- 卡片顶部品牌按钮 -->
    <el-button type="primary" size="defalut" icon="Plus">添加品牌</el-button>
    <!-- 表格组件 -->
    <el-table style="margin: 10px 0px" border :data="trademarkArr">
      <el-table-column
        label="序号"
        width="80px"
        align="center"
        type="index"
      ></el-table-column>
      <el-table-column label="品牌名称" prop="tmName"></el-table-column>
      <el-table-column label="品牌LOGO">
        <template #="{ row, $index }">
          <img
            :src="row.logoUrl"
            alt="LOGO"
            style="width: 100px; height: 100px"
          />
        </template>
      </el-table-column>
      <el-table-column label="品牌操作">
        <template #="{ row, $index }">
          <el-button size="small" icon="Edit" color="red"></el-button>
          <el-button size="small" icon="Delete" color="purple"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页器 -->
    <!-- 分页器组件
        pagination
        v-model:current-page:设置分页器当前页码
        v-model:page-size:设置每一个展示数据条数
        page-sizes:用于设置下拉菜单数据
        background:设置分页器按钮的背景颜色
        layout:可以设置分页器六个子组件布局调整
    -->
    <el-pagination
      :pager-count="9"
      v-model:current-page="pageNo"
      v-model:page-size="limit"
      :page-sizes="[3, 5, 7, 9]"
      :background="true"
      layout="prev, pager, next, jumper,->,sizes,total"
      :total="total"
    />
  </el-card>
</template>
        
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { reqHasTrademark } from '@/api/product/trademark'
let trademarkArr = ref([{}, {}, {}])

const pageNo = ref<number>(1)
const limit = ref<number>(3)
let total = ref<number | string>(100)
// 获取已有品牌的接口封装为一个函数：在任何情况下获取数据，调用该函数即可
const getHasTrademark = async () => {
  const result = await reqHasTrademark(pageNo.value, limit.value)
  if (result.code == 200) {
    total.value = result.data.total
    trademarkArr.value = result.data.records
  }
}
// 组件挂载完毕的钩子
onMounted(() => {
  getHasTrademark()
})

const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`)
}
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`)
}
</script>
        
<style lang="scss" scoped>
</style>